

package com.teaching.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.common.Result;

import com.teaching.dto.CourseDTO;
import com.teaching.entity.Course;
import com.teaching.mapper.CourseMapper;
import com.teaching.service.CourseService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;


/**
 * 课件表
 *
 * @author xubb
 * @date 2021-03-22 15:28:38
 */
@RestController
@RequestMapping("/course")
@Api(value = "course", tags = "课件表管理")
public class CourseController {
    @Resource
    private CourseService courseService;

    @Resource
    private CourseMapper courseMapper;

    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/getCourseList")
    public Result<IPage<Course>> getCourseList(@RequestBody CourseDTO dto) {
        Page<Course> page = new Page<>(dto.getPageNo(), dto.getPageSize());
        Course Course = new Course();
        BeanUtil.copyProperties(dto, Course);
        return Result.success(courseMapper.getCourseList(page, Course));
    }


    /**
     * 通过id查询
     *
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @PostMapping("/getCourseInfo")
    public Result getCourseInfo(@RequestBody Course course) {
        return Result.success(courseService.getById(course.getId()));
    }

    /**
     * 新增
     *
     * @param course
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody Course course) {
        return Result.success(courseService.save(course));
    }

    /**
     * 修改
     *
     * @param course
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/updateById")
    public Result updateById(@RequestBody Course course) {

        return Result.success(courseService.updateById(course));
    }

    /**
     * 通过id删除
     *
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @PostMapping("/removeById")
    public Result removeById(@RequestBody Course course) {
        return Result.success(courseService.removeById(course.getId()));
    }
}
